package com.zj.study.pojo;

import com.baomidou.mybatisplus.core.metadata.IPage;
import java.io.Serializable;
import java.util.List;
import lombok.Getter;
import lombok.ToString;
import org.springframework.lang.NonNull;

/**
 * @author 赵赳
 * @since 2021/9/17 14:28
 */
@Getter
@ToString
public class FinalPageVO1<T> implements Serializable {

  /**
   * 分页信息
   */
  @NonNull
  private final PageInfoVO pageInfoVO;

  @NonNull
  private final Boolean success;

  @NonNull
  private final String code;

  @NonNull
  private final String msg;

  private final List<T> data;


  public FinalPageVO1(@NonNull Boolean success, @NonNull String code,
      @NonNull String msg, PageInfoVO pageInfoVO, List<T> data) {
    this.success = success;
    this.code = code;
    this.msg = msg;
    this.data = data;
    this.pageInfoVO = pageInfoVO;
  }

  @NonNull
  public static <T> FinalPageVO1<T> ok(@NonNull IPage<T> page) {
    return ok(page, page.getRecords(), RespStatusEnum.OK.getMsg());
  }

  @NonNull
  public static <T> FinalPageVO1<T> ok(@NonNull IPage<?> page, @NonNull List<T> data) {
    return ok(page, data, RespStatusEnum.OK.getMsg());
  }

  @NonNull
  public static <T> FinalPageVO1<T> ok(
      @NonNull IPage<?> page, @NonNull List<T> data, @NonNull String msg
  ) {
    return ok(data, msg,new PageInfoVO()
        .setPage((int) page.getCurrent())
        .setTotalPage((int) page.getPages())
        .setSize((int) page.getSize())
        .setTotalSize((int) page.getTotal()));
  }

  @NonNull
  public static <T> FinalPageVO1<T> ok(
       @NonNull List<T> data, @NonNull String msg,@NonNull PageInfoVO pageInfo
  ) {
    return new FinalPageVO1<>(true, RespStatusEnum.OK.getCode(), msg, pageInfo, data);
  }


}
